﻿using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;

namespace FlitBit.IoC.Mvc
{
	public class DependencyResolver : IDependencyResolver
	{	 
		public DependencyResolver()
		{
		}

		public object GetService(Type serviceType)
		{
			return Container.Root.NewUntyped(LifespanTracking.External, serviceType);
		}

		public IEnumerable<object> GetServices(Type serviceType)
		{
			var enumerable = typeof(IEnumerable<>).MakeGenericType(serviceType);
			return (IEnumerable<object>) Container.Root.NewUntyped(LifespanTracking.External, enumerable);
		}

		public IDependencyScope BeginScope()
		{
			return new DepedencyScopeResolver(Container.Root.MakeChildContainer(CreationContextOptions.None));
		}

		public void Dispose()
		{
		}
	}
}
